<!--include js/css-->
<?php Yii::app()->clientScript->registerCoreScript('cookie'); ?>
<?php Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/stock/stock.css'); ?>
<?php Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/stock/validation.css'); ?>

<!--Sub-menu-->
<?php require '_submenu.php'; ?>

<!---------------------------------------------------------------------------------->
<!--Yii's default script-->
<?php
Yii::app()->clientScript->registerScript(
        'search', "
        $('.search-form form').submit(function(){
            $.fn.yiiGridView.update('stock-grid', {
                data: $(this).serialize()
            });
            return false;
        });
        "
);
?>
<h1>Validation</h1>

<p>
    Filter which stocks to validate
</p>

<div class="search-form">
    <?php
    $this->renderPartial('_searchAndValidate', array(
        'model' => $model,
    ));
    ?>
</div><!-- search-form -->
<!--End of Yii's default script and code -->
<!---------------------------------------------------------------------------------->
<?php
    $afterUpdate = "function(id, data) {
        if($.cookie('isValidating') == 1) {
            $.ajax({
            type: 'POST',
            url: '" . Yii::app()->createUrl('stock/dataValidate') ."',
            success: function(data) {
                showErrors(data);
                $('#status').text('Done');
            },
            error: function() {
                alert('We have some error. Please try again!');
            }
        });
        } else {
            $('#status').text('Done');
            }
        }";
    $this->renderPartial('_inlineEditor', array(
        'model' => $model,
        'dataProvider' => $dataProvider,
        'add' => false,
        'filter' => null,
        'afterUpdate' => $afterUpdate,
    ))
?>
<script type="text/javascript">
    if($.cookie('isValidating') == 1) {
            $.ajax({
            type: 'POST',
            url: '<?php echo Yii::app()->createUrl('stock/dataValidate'); ?>',
            success: function(data) {
                showErrors(data);
                $('#status').text('Done');
            },
            error: function() {
                alert('We have some error. Please try again!');
            }
        });
        }
</script>